package com.zenithmind.chat.pojo.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

/**
 * AI对话消息创建DTO
 * 遵循单一职责原则，专门用于创建消息
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "AI对话消息创建DTO")
public class AiChatMessageCreateDTO extends BaseDTO {
    
    @NotBlank(message = "对话ID不能为空")
    @Schema(description = "对话ID", required = true)
    private String chatId;
    
    @NotBlank(message = "消息内容不能为空")
    @Size(max = 10000, message = "消息内容长度不能超过10000个字符")
    @Schema(description = "消息内容", required = true)
    private String content;
    
    @Schema(description = "父消息ID")
    private String parentId;
    
    @Schema(description = "消息类型(text-文本,image-图片,file-文件)", example = "text")
    private String messageType = "text";
    
    @Schema(description = "附件URL列表")
    private java.util.List<String> attachments;
    
    @Schema(description = "消息元数据(JSON格式)")
    private String metadata;
    
    @Override
    public boolean isValid() {
        // 验证消息类型
        if (messageType != null && 
            !messageType.matches("^(text|image|file)$")) {
            return false;
        }
        
        // 如果是图片或文件类型，必须有附件
        if (("image".equals(messageType) || "file".equals(messageType)) &&
            (attachments == null || attachments.isEmpty())) {
            return false;
        }
        
        return super.isValid();
    }
    
    @Override
    public String getBusinessKey() {
        return chatId + ":" + System.currentTimeMillis();
    }
}
